import React from "react";
import {useNavigate} from 'react-router-dom'
import { Form, Input, Button, Toast } from "antd-mobile";
import request from '../../axios/api.jsx'
const Index = () => {
  let navigate=useNavigate()
  const onFinish=async(values)=>{
    const res= await request.post('/api/login',values)
    const {code,data}=res.data
    if(code===200){
      console.log(res)
      localStorage.setItem('token',data.token)
      localStorage.setItem('username',data.userInfo.username)
      localStorage.setItem('avatar',data.userInfo.avatar)
      navigate('/')
    }
  }
  return (
    <div>
      <Form
        onFinish={onFinish}
        layout="horizontal"
        footer={
          <Button block type="submit" color="primary" size="large">
            提交
          </Button>
        }
      >
        <Form.Item
          name="username"
          label="姓名"
          rules={[{ required: true, message: "姓名不能为空" }]}
        >
          <Input  placeholder="请输入姓名" />
        </Form.Item>
        <Form.Item
          name="password"
          label="密码"
          rules={[{ required: true, message: "姓名不能为空" }]}
        >
          <Input  placeholder="请输入姓名" />
        </Form.Item>
      </Form>
    </div>
  );
};

export default Index;
